<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--<jsp:useBean id="clsConn" class="utility.connections" scope="session"></jsp:useBean>-->
<%@page import = "utility.connections" %>
<script type="text/javascript" src="../../js/checkdate.js"></script>
<script type="text/javascript">
			function setCategoria()
			{
				dipendente = document.form1.dipendente.value; 
				cat = document.form1.cmbCat.value;
				location.href = "effettua.jsp?subcat=0&cat="+cat+"&dipendente="+dipendente;
			}
			
			function setSubCategoria()
			{
				cat = document.form1.cmbCat.value;
				subcat = document.form1.cmbSCat.value;
				dipendente = document.form1.dipendente.value; 
				location.href = "effettua.jsp?cat="+cat+"&subcat="+subcat+"&dipendente="+dipendente;
			}
			function submit(formName)
			{
				document.forms[formName].submit();	
			}
</script>
<%! 
	String cat, subcat, codice="",dipendente="",stanza="",nomestanza="",posstanza="",datainizio="",datafine="", matricola="",codicefiscale="",cognome="",nome="",user="",qry=""; 
	ResultSet rs;
%>
<%
	if (session.getAttribute("user")==null)
		response.sendRedirect("loginerr.jsp");
	
	user = session.getAttribute("user").toString().toLowerCase();
	dipendente=request.getParameter("dipendente");
	
%>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EFFETTUA RICHIESTA</title>
<script type="text/javascript" src="../../js/immagini.js"></script>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="js/immagini.js"></script>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td align="center"><div align="left">
          <p class="style3">		  </p>
        </div></td>
        </tr>
       <td><div>
	</div></td>
      <tr>
        <td class="style1"><p align="center"><strong>Inserire sottocategoria bene e motivazione: </strong></p></td>
      </tr>
      
      <tr>
        <td class="style1"><div align="center">
          <form name="form1" method="post" action ="../../Insert_richiesta">
          <table width="100%" border="0">
          <tr>
	          <td><div align="right">CATEGORIA:</div></td>
	          <td>
			  	<select name="cmbCat" onChange="setCategoria();">
					<option value="">SELEZIONA UNA CATEGORIA</option>
					<%
						cat    = "" + request.getParameter("cat");
						subcat = "" + request.getParameter("subcat");
						user = "" + session.getAttribute("user").toString().toLowerCase();
						
						Connection  conn;
						Statement   st;
						ResultSet   rs;
						String 		qry;
						conn=connections.getConnection();
						st=connections.getStatement();
						qry = "SELECT * FROM CATEGORIABENE ORDER BY SIGLA";
						out.println(qry);
						rs = st.executeQuery(qry);
						while (rs.next())
						{
							String strCat = rs.getString("SIGLA");
							if(cat.equalsIgnoreCase(strCat))
								out.println("<option selected =\"selected\" value=\"" + strCat + "\">" + strCat + " </option>");
							else
								out.println("<option value=\"" + strCat + "\">" + strCat + "</option>");
						}		
						rs.close();
						st.close();
					%>
	          	</select>			  </td>
	        </tr>
	        <tr>
	          <td><div align="right">SOTTOCATEGORIA:</div></td>
	          <td>
			  	<select name="cmbSCat" onChange="setSubCategoria();">
					<option value="">SELEZIONA UNA SOTTOCATEGORIA</option>
					<%
						if(!cat.equals(""))
						{
							conn=connections.getConnection();
							st=connections.getStatement();
							qry = "SELECT * FROM SOTTOCATEGORIABENE WHERE CATEGORIABENE='"+cat+"' ORDER BY NOME";
							rs = st.executeQuery(qry);
							while (rs.next())
							{
								String strSubCat = rs.getString("codice");
								if(strSubCat.equalsIgnoreCase(subcat))
									out.println("<option selected=\"selected\" value=\"" + rs.getString("CODICE") + "\">" + rs.getString("NOME") + "</option>");
								else
									out.println("<option value=\"" + rs.getString("CODICE") + "\">" + rs.getString("NOME") + "</option>");
							}
							rs.close();
							st.close();
						}
					%>
				</select>			  </td>
	        </tr>
            <tr>
              <td width="16%"><div align="right">MOTIVAZIONE:</div></td>
              <td width="27%"><div align="left">
                <label>
                <textarea name="motivazione"></textarea>
                </label>
                <label>
                <input name="dipendente" value=<%=dipendente %> style="visibility: hidden;" >
             	</label>
              </div></td>
              </tr>
            <tr>
              <td>&nbsp;</td>
              <td>
              <input type="button" value="INDIETRO" onclick="javascript:history.back()">
              <input type="button" value="INVIA RICHIESTA" onclick="javscript:submit('form1')">
              <div align="right"></div></td>
            </tr>
          </table>
        </form>        </tr>
      <tr>
        <td height="73" class="style1"><div align="center"></div></td>
        </tr>
    </table>
  </tr>
</table>
</body>
</html>
